package com.huaxin.hxmodulesystem.controller;

import com.huaxin.hxmodulesystem.dto.ResponseResult;
import com.huaxin.hxmodulesystem.dto.request.AddElectricianOrganizationFamilyReqDTO;
import com.huaxin.hxmodulesystem.dto.response.ElectricianScopeDTO;
import com.huaxin.hxmodulesystem.service.ElectricianOrganizationFamilyService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "电工与家庭或企业的关系")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/sys/electricianOrganizationFamily")
public class ElectricianOrganizationFamilyController {
    private final ElectricianOrganizationFamilyService electricianOrganizationFamilyService;

    // 添加电工组织关系
    @Operation(summary = "添加电工组织关系", description = "添加电工组织关系")
    @PostMapping("/addElectricianOrganizationFamily")
    public ResponseResult<Boolean> addElectricianOrganizationFamily(@RequestBody AddElectricianOrganizationFamilyReqDTO in) {
        return electricianOrganizationFamilyService.addElectricianOrganizationFamily(in);
    }

    //删除工电工组织关系
    @Operation(summary = "删除电工组织关系", description = "删除电工组织关系")
    @DeleteMapping("/deleteElectricianOrganizationFamily")
    public ResponseResult<Boolean> deleteElectricianOrganizationFamily(@Parameter(name = "id", description = "工电工组织关系ID") @RequestParam(value = "id", required = true) String id) {
        return electricianOrganizationFamilyService.deleteElectricianOrganizationFamily(id);
    }

    @Operation(summary = "根据电工id和组织（家庭）ID删除关系", description = "根据电工id和组织（家庭）ID删除关系")
    @DeleteMapping("/deleteByElectricianIdAndOrgId")
    public ResponseResult<Boolean> deleteByElectricianIdAndOrgId(@Parameter(name = "electricianId", description = "电工ID") @RequestParam(value = "electricianId", required = true) String electricianId,
                                                                 @Parameter(name = "orgId", description = "组织ID") @RequestParam(value = "orgId", required = false) String orgId,
                                                                 @Parameter(name = "familyId", description = "家庭ID") @RequestParam(value = "familyId", required = false) String familyId) {
        return electricianOrganizationFamilyService.deleteByElectricianIdAndOrgId(electricianId, orgId, familyId);
    }


    @Operation(summary = "聚合查询所有电工组织关系", description = "聚合查询所有电工组织关系")
    @GetMapping("/electricianScopeList")
    public ResponseResult<List<ElectricianScopeDTO>> electricianScopeList(String electricianId) {
        return electricianOrganizationFamilyService.electricianScopeList(electricianId);
    }

    @Operation(summary = "通过家庭ID和组织ID查询电工", description = "通过家庭ID和组织ID查询电工")
    @GetMapping("/getElectriciansByFamilyIdAndOrgId")
    public ResponseResult<List<String>> getElectriciansByFamilyIdAndOrgId(@Parameter(name = "familyId", description = "家庭ID") @RequestParam(value = "familyId", required = true) String familyId,
                                                                          @Parameter(name = "orgId", description = "组织ID") @RequestParam(value = "orgId", required = true) String orgId) {
        return electricianOrganizationFamilyService.getElectriciansByFamilyIdAndOrgId(familyId, orgId);
    }

    @Operation(summary = "通过组织ID查询电工", description = "通过组织ID查询电工")
    @GetMapping("/getElectriciansByOrgId")
    public ResponseResult<List<String>> getElectriciansByOrgId(@Parameter(name = "orgId", description = "组织ID") @RequestParam(value = "orgId", required = true) String orgId) {
        return electricianOrganizationFamilyService.getElectriciansByOrgId(orgId);
    }
}
